package com.qing.common.viewholder;

import android.graphics.drawable.Drawable;
import android.view.View;

import androidx.annotation.NonNull;

import com.qing.common.base.BaseAdapter;
import com.qing.common.base.BaseViewHolder;
import com.qing.common.databinding.ItemEmptyLayoutBinding;

public class DefaultEmptyViewHolder extends BaseViewHolder<Integer, ItemEmptyLayoutBinding> {

    private CharSequence mEmptyText;

    private Drawable mEmptyImage;

    public DefaultEmptyViewHolder(@NonNull ItemEmptyLayoutBinding binding) {
        super(binding);
    }

    public DefaultEmptyViewHolder setEmptyText(CharSequence emptyText) {
        mEmptyText = emptyText;
        return this;
    }

    public DefaultEmptyViewHolder setEmptyImage(Drawable emptyImage) {
        mEmptyImage = emptyImage;
        return this;
    }

    @Override
    public void bind(@NonNull @BaseAdapter.EmptyViewType Integer emptyType) {
        switch (emptyType) {
            case BaseAdapter.EMPTY_TYPE_NONE:
                getBinding().getRoot().setVisibility(View.GONE);
                break;
            case BaseAdapter.EMPTY_TYPE_IMAGE:
                getBinding().emptyImage.setImageDrawable(mEmptyImage);
                getBinding().emptyImage.setVisibility(View.VISIBLE);
                getBinding().emptyText.setVisibility(View.GONE);
                break;
            case BaseAdapter.EMPTY_TYPE_TEXT:
                getBinding().emptyText.setText(mEmptyText);
                getBinding().emptyText.setVisibility(View.VISIBLE);
                getBinding().emptyImage.setVisibility(View.GONE);
        }
    }
}
